<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">

          <a-form :form="form">
            <a-row>
              <a-divider>基本信息</a-divider>
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item label="所属单位" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--                  <j-select-category v-decorator="['assetFixedCategoryId']"></j-select-category>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
              <a-col :xs="24" :sm="12">
                <a-form-item label="请选择资产分类" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <j-search-select-tag type="list" v-decorator="['assetType']"
                                       :trigger-change="true"  dict="gf_zcgl_asset_type" :disabled="disableSubmit"
                                       placeholder="请选择资产分类"/>
                </a-form-item>
              </a-col>
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="物资编码">-->
<!--                  <a-input placeholder="请输入产品编码" v-decorator="['code', {}]" />-->
<!--                </a-form-item>-->
<!--              </a-col>-->
              <a-col :xs="24" :sm="12">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="物资名称">
                  <a-input placeholder="请输入物资名称" v-decorator="['name', {}]" />
                </a-form-item>
              </a-col>
              <a-col :xs="24" :sm="12">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="规格型号">
                  <a-input placeholder="请输入规格型号" v-decorator="['specifications', {}]" />
                </a-form-item>
              </a-col>



              <a-col :xs="24" :sm="12">
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="单位">-->
<!--                  <a-input placeholder="请输入单位" v-decorator="['unit', {}]" />-->
<!--                </a-form-item>-->
                <a-form-item label="请选择单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <j-search-select-tag type="list" v-decorator="['unit',validatorRules.unit]"
                                       :trigger-change="true"  dict="zcgl_dw" :disabled="disableSubmit"
                                       placeholder="请选择资产单位"/>
                </a-form-item>
              </a-col>
              <a-col :xs="24" :sm="12">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="数量">
                  <a-input-number placeholder="请输入数量" v-decorator="['amount', {}]" style="width: 100%"/>
                </a-form-item>
              </a-col>

              <a-col :xs="24" :sm="12">

                <a-form-item label="存储地" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <!--              <j-search-select-tag v-decorator="['storage', validatorRules.storage]"-->
                  <!--                                   :trigger-change="true" dict="zcgl_asset_fixed_category,name,id"-->
                  <!--                                   :disabled="disableSubmit"-->
                  <!--                                   placeholder="请选择存储地"/>-->

                  <j-select-cang-ku v-decorator="['assetFixedCategoryId', validatorRules.assetFixedCategoryId]"></j-select-cang-ku>
                </a-form-item>
              </a-col>


              <a-col :xs="24" :sm="12">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="单价">
                  <a-input-number v-decorator="[ 'price', {}]" style="width: 100%"/>
                </a-form-item>
              </a-col>
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="合价">-->
<!--                  <a-input-number v-decorator="[ 'total', {}]" style="width: 100%"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="采购部门">-->
<!--                  <a-input placeholder="请输入采购部门" v-decorator="['purchasingDepartment', {}]" />-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="采购日期">-->
<!--                  <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'purchaseDate', {}]" />-->
<!--                </a-form-item>-->
<!--              </a-col>-->
              <a-col :xs="24" :sm="12">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  label="图片">
                  <!--            <a-input placeholder="请输入图片" v-decorator="['image', {}]" />-->
                  <!--            <j-image-upload  v-decorator="['image', {}]"></j-image-upload>-->
                  <j-image-upload text="上传" v-decorator="['image', {}]" :isMultiple="true" :number="6"></j-image-upload>
                </a-form-item>
              </a-col>
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="材质说明">-->
<!--                  <a-input placeholder="请输入材质说明" v-decorator="['description', {}]" />-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="楼层">-->
<!--                  <a-input placeholder="请输入楼层" v-decorator="['floor', {}]" />-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="尺寸">-->
<!--                  <a-input v-decorator="[ 'assetSize', {}]" />-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="款式">-->
<!--                  <a-input placeholder="请输入款式" v-decorator="['assetStyle', {}]" />-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="技术参数">-->
<!--                  <a-input placeholder="请输入技术参数" v-decorator="['technicalParameters', {}]" />-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="品牌">-->
<!--                  <a-input placeholder="请输入品牌" v-decorator="['brand', {}]" />-->
<!--                </a-form-item>-->
<!--              </a-col>-->
              <a-col :span =24>
                <a-form-item
                  :labelCol="labelCol2"
                  :wrapperCol="wrapperCol2"
                  label="备注">
                  <a-textarea placeholder="请输入备注" v-decorator="['remark', {}]"  style="height: 80px"/>
                </a-form-item>
              </a-col>
<!--              <a-divider>折旧信息</a-divider>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="原值">-->
<!--                  <a-input-number v-decorator="[ 'originalCost', {}]" style="width: 100%"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="累计折旧">-->
<!--                  <a-input-number v-decorator="[ 'accumulativeDiscount', {}]" style="width: 100%"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="净残值率">-->
<!--                  <a-input-number v-decorator="[ 'residualValueRate', {}]" style="width: 100%" @blur="calculationResidualValue"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="净残值">-->
<!--                  <a-input-number v-decorator="[ 'residualValue', {}]" style="width: 100%"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="折旧方法">-->
<!--                  <j-dict-select-tag  v-decorator="['depreciationMethod', {}]" :triggerChange="true" placeholder="请输入用户性别"-->
<!--                                      dictCode="depreciation_method"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="月折旧率">-->
<!--                  <a-input-number v-decorator="[ 'monthDepreciationRate', {}]" style="width: 100%" @blur="calculationMonthDepreciation"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="月折旧额">-->
<!--                  <a-input-number v-decorator="[ 'monthDepreciation', {}]" style="width: 100%"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
<!--              <a-col :xs="24" :sm="12">-->
<!--                <a-form-item-->
<!--                  :labelCol="labelCol"-->
<!--                  :wrapperCol="wrapperCol"-->
<!--                  label="预计使用年限">-->
<!--                  <a-input-number v-decorator="[ 'expectedServiceLife', {}]" style="width: 100%"/>-->
<!--                </a-form-item>-->
<!--              </a-col>-->
            </a-row>
          </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import moment from 'moment'
import JImageUpload from '../../../components/jeecg/JImageUpload'
import JSelectCategory from '../../../components/jeecgbiz/JSelectCategory'
import JSearchSelectTag from '../../../components/dict/JSearchSelectTag'
import JSelectCangKu from '../../../components/jeecgbiz/JSelectCangKu'



export default {
  name: 'AssetFixedModal',
  components: { JSelectCategory, JImageUpload,JSearchSelectTag,JSelectCangKu },
  data () {
    return {
      title: '操作',
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {


        assetFixedCategoryId: {
          rules: [
            { required: true, message: '请选择存储地!'},
          ]
        },
        unit: {
          rules: [
            { required: true, message: '请选择单位!'},
          ]
        },

      },
      url: {
        add: '/zcgl/assetFixed/add',
        edit: '/zcgl/assetFixed/edit'
      }
    }
  },
  created () {
  },
  methods: {
    add () {
      this.edit({})
    },
    edit (record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      this.$nextTick(() => {
        let keys = Object.keys(this.form.formItems);
        // this.form.setFieldsValue(pick(this.model, 'name','assetFixedCategoryId','specifications', 'unit', 'amount', 'price', 'total', 'image', 'description', 'floor', 'assetSize', 'assetStyle', 'technicalParameters', 'brand', 'remark'))
        this.form.setFieldsValue(pick(this.model, keys))
        //时间格式化
        this.form.setFieldsValue({ purchaseDate: this.model.purchaseDate ? moment(this.model.purchaseDate) : null })
      })

    },
    close () {
      this.$emit('close')
      this.visible = false
    },
    handleOk () {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model, values)
          if (!this.model.id) {
            formData.status = 0
          }
          //时间格式化
          formData.purchaseDate = formData.purchaseDate ? formData.purchaseDate.format('YYYY-MM-DD HH:mm:ss') : null

          console.log(formData)
          httpAction(httpurl, formData, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.close()
          })

        }
      })
    },
    handleCancel () {
      this.close()
    },
    calculationResidualValue(){
      let originalCost = this.form.getFieldValue('originalCost')
      let residualValueRate = this.form.getFieldValue('residualValueRate')
      let residualValue =''
      if (originalCost != undefined && originalCost != '' && residualValueRate != undefined && residualValueRate != '') {
        residualValue = originalCost * residualValueRate
      }
      this.form.setFieldsValue({
        residualValue: residualValue
      })
    },
    calculationMonthDepreciation(){
      let originalCost = this.form.getFieldValue('originalCost')
      let monthDepreciationRate = this.form.getFieldValue('monthDepreciationRate')
      let monthDepreciation=''
      if (originalCost != undefined && originalCost != '' && monthDepreciationRate != undefined && monthDepreciationRate != '') {
        monthDepreciation = originalCost * monthDepreciationRate
      }
      this.form.setFieldsValue({
        monthDepreciation: monthDepreciation
      })
    }

  }
}
</script>

<style lang="less" scoped>

</style>